<template>
  <!-- 仓库记录   盘点 -->
  <div>
    <div ref="search" class="app-search">
      <el-row>
        <el-col :span="16" class="margin-top">
          <Search :data="selections" :data-value="timeVlaue" :attribute="'createdTime'" @change="handleTypeChange" @dateChange="handleDateChange" />
        </el-col>
      </el-row>
    </div>
    <div class="margin-top box-show">
      <el-table :data="list" border :row-class-name="tableColor" :height="innerHeight">
        <el-table-column label="盘点单号" prop="offsetOrderNo" :show-overflow-tooltip="true" />
        <el-table-column label="仓库" prop="warehouseName" :show-overflow-tooltip="true" />
        <el-table-column label="时间" prop="warehouseOutTime" :show-overflow-tooltip="true" />
        <el-table-column label="操作员" prop="operator" :show-overflow-tooltip="true" />
        <el-table-column label="数量" prop="totalNum" :show-overflow-tooltip="true" />
        <el-table-column label="操作">
          <template slot-scope="{ row }">
            <el-button type="text" @click="detailsHnadle(row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        :page-num="queryParams.page"
        :page-size="queryParams.pageSize"
        :on-change="handlePaginationChange"
        :total="total"
      />
    </div>
    <InventoryDialog v-if="visible" :visible.sync="visible" :current-row="currentRow" @handleClose="handleClose" />
  </div>
</template>
<script>
import Search from "@/components/Search";
import { all } from "@/config";
import InventoryDialog from "./inventoryDialog";
import { tableColor } from '@/utils/common.js';
export default {
  components: {
    Search,
    InventoryDialog,
  },
  data() {
    return {
      tableColor,
      innerHeight: null,
      queryParams: {
        page: 1,
        pageSize: this.$store.state.commonsettings.maxPageSize,
      },
      total: 0,
      visible: false,
      warehousingVisible: false,
      visibleDetails: false,
      selections: all,
      timeVlaue: "",
      query: {
        status: "全部",
        type: "盘点",
      },
      list: [],
      currentRow: {},
      currentRowDetails: {},
      startReturnVisitContent: {},
      statrVisible: false,
      isDetails: false,
    };
  },
  computed: {
  },
  mounted() {
    this.timeVlaue = "all";
    this.getList();
    this.$nextTick(() => {
      var topHeight = (this.$refs.search.clientHeight + 160 + 200);
      var winHeight = document.body.clientHeight || document.documentElement.clientHeight;
      this.innerHeight = winHeight - topHeight;
    });
  },
  methods: {
    async getList() {
      const query = JSON.parse(JSON.stringify(this.query));
      if (query.status === "全部") query.status = undefined;
      const res = await this.$api['warehouse/warehouseRecords/writeoff']({ ...this.queryParams, query: query });
      if (res.code !== 200) return this.$message.error(res.msg);
      this.list = res.data.result;
      this.total = res.data.total;
    },
    handlePaginationChange(pagination) {
      this.queryParams = { page: pagination.pageNum, pageSize: pagination.pageSize };
      this.getList();
    },
    handleDateChange(item) {
      this.queryParams.page = 1;
      Object.assign(this.query, item);
      this.getList();
    },
    handleTypeChange(item) {
      this.queryParams.page = 1;
      Object.assign(this.query, item);
      this.getList();
    },
    async detailsHnadle(row) {
      const res = await this.$api['warehouse/warehouseRecords/getWriteoff']({ id: row.id });
      if (res.code !== 200) return this.$message.error(res.msg);
      this.currentRow = res.data;
      this.visible = true;
    },
    handleClose() {
      this.visible = false;
    },
  },
};
</script>
<style scoped lang="scss">
.margin-top{
    margin-top: 10px;
}
</style>
